<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title><?php echo $title; ?></title>
    <base href="<?php echo base_url(); ?>"/>
    <link href="style/base.css" rel="stylesheet" type="text/css" />
    <link href="style/common.css" rel="stylesheet" type="text/css" />
    <link href="style/houtai.css" rel="stylesheet" type="text/css" />
    <link href="style/my.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <script src="js/organictabs.jquery.js"></script>
    <script type="text/javascript" src="js/Common.js"></script>
    <script type="text/javascript" src="js/Validation.js"></script>
    <script type="text/javascript" src="jscript/WdatePicker.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>
    <script type="text/javascript" src="js/jquery.blockUI.js"></script>
    <script type="text/javascript">
        var curImg = "curImg";
        var lastcardid = "";
        $(function () {
            loadTable();
            $("input[name='1']").bind("change", loadTable);
            loadUserInfo();
            $("#btnNext").bind("click", save);
            $("#fileHead").bind("change", loadImg);
            bindSubmit();
        });


        function loadTable() {
            var cardid = $("input[name='1']:checked").val();
            var imgsrcs = getImgSrcs();
            var params = {
                cardid: cardid,
                imgsrcs: imgsrcs,
                lastcardid: lastcardid
            };
            lastcardid = cardid;

            $.ajax({
                type: "post",
                url: "index.php/login/getCardTable",
                dataType: "json",
                data: params,
                success: function (data) {
                    $("#tableMain").html(data.card);
                    var tableClass = $("#tableMain table:first").attr("class");

                    bindImgFile(tableClass);
                }
            });
        }
        function getImgSrcs() {
            var imgSrcs = "";
            $("#tableMain img").each(function () {
                var src = $(this).attr("src");
                if (src.indexOf("images/") == -1)
                    imgSrcs += $(this).attr("src") + ";";
            });
            return imgSrcs;
        }
        function loadUserInfo() {
            $.ajax({
                type: "post",
                url: "index.php/login/getUserInfo",
                dataType: "json",
                success: function (data) {
                    if (!IsEmpty(data.cardid)) {
                        $("input[name='1'][value='" + data.cardid + "']").trigger("click");
                        lastcardid = data.cardid;
                    } else {
                        lastcardid = 1;
                    }
                    if (!IsEmpty(data.cardcontent))
                        $("#tableMain").html(data.cardcontent);
                }
            });
        }


        function save() {
            var cardid = $("input[name='1']:checked").val();
            var cardcontent = $("#tableMain").html();
            var params = {
                cardid: cardid,
                cardcontent: cardcontent
            };
            var url = "index.php/login/saveCard";
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: params,
                success: function (data) {
                    if (data.ReturnCode == 1) {
                        if ($("#btnNext").attr("src") == "images/bc_inp.jpg") {
                            alert('保存成功');
                            window.location = "<?php echo base_url()?>index.php/manage/mcard";
                        }
                        else {
                            window.location = "<?php echo base_url()?>index.php/login/show";
                        }

                    } else {
                        alert('保存失败');
                    }
                }
            });
        }

        function bindSubmit() {
            var options = {
                beforeSubmit: showRequest,  //提交前处理
                success: showResponse,  //处理完成
                resetForm: false,
                dataType: 'json'
            };

            $('#formCard').submit(function () {

                $(this).ajaxSubmit(options);
                return false;
            });
        }
        function showRequest(formData, jqForm, options) {
            return true;
        }

        function showResponse(data, statusText) {
            if (data.ReturnCode == 1) {
                $("." + curImg).attr("src", data.src);
            } else {
                alert(data.Msg);
            }
            return false;
        }

        function bindImgFile(cname) {
            $("." + cname + " img").bind("click", function () {
                $(this).parents("table").find("img").removeClass(curImg);
                $(this).addClass(curImg);
                $("#fileHead").trigger("click");
            });
        }

        function loadImg() {
            var fileName = $("#fileHead").val();
            var ext = fileName.substr(fileName.indexOf(".")).toLowerCase();
            if (ext != ".gif" && ext != ".jpg" && ext != ".jpeg" && ext != ".png" && ext != "") {
                alert("图片格式无效");
                return;
            }
            if (!IsEmpty(fileName)) {
                $("#formCard").submit();
                return;
            }
        }
    </script>
</head>
<body>
<!-- head S-->
<?php
include 'header.php';
?>
<!-- head E-->

<div class="houtai_content mt_10 clearfix">
    <!-- 侧栏 开始 -->
    <?php
    include 'member_left.php';
    ?>
    <!-- 侧栏 结束 -->
    <div class="houtai_main">
        <div class="houtai_mtk">
            <div class="houtai_main_tit">用户中心—模特档案</div>
            <div class="houtai_mtk_cnt">
<form id="formCard" action="index.php/login/uploadImg" method="post" enctype="multipart/form-data">

    <!-- 04 开始 -->
        <input type="file" id="fileHead" name="mypic" style="display: none">

        <!-- 模特卡管理 开始 -->
        <div class="moteka_mb">
            <ul>
                <li><img src="images/moban_01.jpg"/> <br/> <span><input id="r1"
                                                                        name="1" type="radio" value="1" checked="checked"/>10幅（竖版）</span>
                </li>
                <li><img src="images/moban_02.jpg"/> <br/> <span><input name="1"
                                                                        type="radio" value="2"/>10幅（竖版）</span></li>
                <li><img src="images/moban_03.jpg"/> <br/> <span><input name="1"
                                                                        type="radio" value="3"/>10幅（竖版）</span></li>
                <li><img src="images/moban_04.jpg"/> <br/> <span><input name="1"
                                                                        type="radio" value="4"/>10幅（竖版）</span></li>
                <li><img src="images/moban_05.jpg"/> <br/> <span><input name="1"
                                                                        type="radio" value="5"/>10幅（竖版）</span></li>
            </ul>
        </div>

        <div class="moban">
            <div id='tableMain' class='divCard'></div>
        </div>

        <?php
        if (!isset($ht)) {
            print "<div class='yindao_inp'>
								<a href='index.php/login/experience'><img src='images/fhsyb_inp.jpg' /></a>
								<img id='btnNext' class='link' src='images/bcxyb_inp.jpg' />
						   </div>";
        } else {
            print "<div class='filter_inp'>
								<img id='btnNext' class='link' src='images/bc_inp.jpg'>
							</div>";
        }
        ?>

        <!-- 模特卡管理 结束 -->
</form>
            </div>
        </div>
    </div>
</div>
<!-- 页脚 开始 -->
<?php include 'footer.php'; ?>
<!-- 页脚 结束 -->
</body>
</html>
